package com.itlong.cloud.property.resource;

import com.itlong.cloud.POJO.DTO.property.PropertyParkCouponGetPageDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyParkCouponSaveDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyParkCouponUpdateDTO;
import com.itlong.cloud.POJO.PO.PropertyParkCouponPO;
import com.itlong.cloud.POJO.VO.property.PropertyParkCouponGetOneVO;
import com.itlong.cloud.POJO.VO.property.PropertyParkCouponGetPageVO;
import com.itlong.cloud.noncore.property.IPropertyParkCouponServiceClient;
import com.itlong.cloud.property.service.IPropertyParkCouponService;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <desc>
 *      智慧停车-停车优惠券管理暴露接口实现类
 * </desc>
 *
 * @createDate 2018/11/06
 */
@RestController
public class PropertyParkCouponServiceResource implements IPropertyParkCouponServiceClient {

    @Autowired
    private IPropertyParkCouponService iPropertyParkCouponService;

    /**
     * <desc>
     *      获取单个优惠券信息
     * </desc>
     *
     * @param parkCouponId 优惠券id
     * @return 单个优惠券信息
     * @author wangzhi
     * @createDate 2018/11/06
     */
    @Override
    @PostMapping(path = "property/coupon/getOneCoupon")
    public PropertyParkCouponGetOneVO getOneCoupon(@RequestParam("parkCouponId") String parkCouponId) throws Exception {
        return iPropertyParkCouponService.getOneCoupon(parkCouponId);
    }

    /**
     * <desc>
     *      分页获取优惠券
     * </desc>
     *
     * @param propertyParkCouponGetPageDTO 分页获取优惠券DTO
     * @return 分页获取优惠券结果
     * @author wangzhi
     * @createDate 2018/11/06
     */
    @Override
    @PostMapping(path = "property/coupon/getCouponPage")
    public Page<PropertyParkCouponGetPageVO> getCouponPage(@RequestBody PropertyParkCouponGetPageDTO propertyParkCouponGetPageDTO) throws Exception {
        return iPropertyParkCouponService.getCouponPage(propertyParkCouponGetPageDTO);
    }

    /**
     * <desc>
     *      获取项目未使用的优惠券数量
     * </desc>
     *
     * @param projectId 项目id
     * @return 项目未使用的优惠券数量
     * @author wangzhi
     * @createDate 2018/11/06
     */
    @Override
    @PostMapping(path = "property/coupon/getAvailableCouponCount")
    public Integer getAvailableCouponCount(@RequestParam("projectId") String projectId) {
        return iPropertyParkCouponService.getAvailableCouponCount(projectId);
    }

    /**
     * <desc>
     *      生成优惠券
     * </desc>
     *
     * @param propertyParkCouponSaveDTO 生成优惠券DTO
     * @return 生成的优惠券
     * @author wangzhi
     * @createDate 2018/11/06
     */
    @Override
    @PostMapping(path = "property/coupon/saveCoupon")
    public List<PropertyParkCouponPO> saveCoupon(@RequestBody PropertyParkCouponSaveDTO propertyParkCouponSaveDTO) throws Exception {
        return iPropertyParkCouponService.saveCoupon(propertyParkCouponSaveDTO);
    }

    /**
     * <desc>
     *      修改优惠券
     * </desc>
     *
     * @param propertyParkCouponUpdateDTO 修改优惠券DTO
     * @return 受影响的行数
     * @author wangzhi
     * @createDate 2018/11/07
     */
    @Override
    @PostMapping(path = "property/coupon/updateCoupon")
    public Integer updateCoupon(@RequestBody PropertyParkCouponUpdateDTO propertyParkCouponUpdateDTO) throws Exception {
        return iPropertyParkCouponService.updateCoupon(propertyParkCouponUpdateDTO);
    }

    /**
     * <desc>
     *      删除优惠券
     * </desc>
     *
     * @param ids 优惠券id，多个用英文","相连
     * @return 1-成功 other-失败
     * @author wangzhi
     * @createDate 2018/11/07
     */
    @Override
    @PostMapping(path = "property/coupon/deleteCoupons")
    public Integer deleteCoupons(@RequestParam("ids") String ids) throws Exception {
        return iPropertyParkCouponService.deleteCoupons(ids);
    }

    /**
     * <desc>
     *      获取导出优惠券
     * </desc>
     *
     * @param propertyParkCouponGetPageDTO 查询参数
     * @return 导出优惠券集合
     * @author wangzhi
     * @createDate 2018/11/07
     */
    @Override
    @PostMapping(path = "property/coupon/getExportData")
    public List<PropertyParkCouponGetPageVO> getExportData(@RequestBody PropertyParkCouponGetPageDTO propertyParkCouponGetPageDTO) throws Exception {
        return iPropertyParkCouponService.getExportData(propertyParkCouponGetPageDTO);
    }
}
